//
//  AddressDetailViewController.m
//  MobileOffice
//
//  Created by jjkj on 16/10/24.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "AddressDetailViewController.h"
#import "PersonMessageViewController.h"


@interface AddressDetailViewController ()
{
    //NSMutableArray *_buttonArr;//button数组
}
@end

@implementation AddressDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setLeftBackNavigation];
    [self setNavigationTitle:_respName];
    [self setRightBackNavigation];
    [self creatView];
    // Do any additional setup after loading the view.
}
#pragma mark - creatView
- (void)creatView{
    //_buttonArr =[NSMutableArray new];
    //头像
    UIImageView *headImageView=[[UIImageView alloc]initWithFrame:CGRectMake((IPHONE_WIDTH-200)/2, 20, 200, 200)];
    [headImageView setImageWithURL:[NSURL URLWithString:_icon] placeholderImage:[UIImage imageNamed:@"k_portrait@2x.png"]];
    [self.view addSubview:headImageView];
    
    
    //添加3个button
    NSMutableArray *titleArr=[NSMutableArray arrayWithArray:@[@"姓名 ：",@"部门 ：",@"岗位 ："]];
    NSMutableArray *arr=[NSMutableArray arrayWithArray:@[_respName,_departName,_postName]];
    if (_mailbox.length) {
        [titleArr addObject:@"邮箱 ："];
        [arr addObject:_mailbox];
    }
    if (_phone.length) {
        [titleArr addObject:@"电话 ："];
        [arr addObject:_phone];
    }
    for (int i=0; i<arr.count; i++) {
        //调整间隔
        CGFloat labelHeight;
        if (IPHONE6P) {
            labelHeight=50;
        }else if (IPHONE6){
            labelHeight=40;
        }else{
            labelHeight=30;
        }
        UILabel *titleLabel=[MyControl creatLabelWithFrame:CGRectMake(labelHeight, headImageView.y+headImageView.height+labelHeight*(i+1), IPHONE_WIDTH-100, 21) text:[NSString stringWithFormat:@"%@%@",titleArr[i],arr[i]]];
        [self.view addSubview:titleLabel];
        
        if (i==arr.count-1) {
            //分割线
            UILabel *line=[[UILabel alloc]initWithFrame:CGRectMake(0, titleLabel.y+titleLabel.height+labelHeight, IPHONE_WIDTH, 1)];
            line.backgroundColor=BACKCOLOR_GRAY;
            [self.view addSubview:line];
            
            NSArray *imageArr=@[@"bodadianhua@2x",@"app@2x",@"fasongduanxin@2x"];
            CGFloat width=(IPHONE_WIDTH-50*3)/4;
            for (int i=0; i<3; i++) {
                UIButton *button=[MyControl creatButtonWithFrame:CGRectMake(width*(i+1)+i*50, line.y+labelHeight, 50, 50) target:self sel:@selector(buttonClick:) tag:100+i image:imageArr[i] title:nil];
                
                [self.view addSubview:button];
                if (_isSafe.integerValue==0) {
                    if (i==0||i==2) {
                        button.hidden=YES;
                    }
                }
                
                //[_buttonArr addObject:button];
            }
        }
    }
}


- (void)buttonClick:(UIButton *)button{
    switch (button.tag) {
        case 100:
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_phone]]];
        }
            break;
        case 101:
        {
            PersonMessageViewController *person=[PersonMessageViewController new];
            person.receEmpName=[_respName copy];
            person.receEmpId=[_respId copy];
            [self.navigationController pushViewController:person animated:YES];
        }
            break;
        case 102:
        {
            //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto://%@",_mailbox]]];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"sms://%@",_phone]]];
        }
            break;
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
